<?php if (!defined('THINK_PATH')) exit();?><!--_meta 作为公共模版分离出去-->
<!DOCTYPE HTML>
<html>
<head>
<title>新增总结</title>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />

<!--[if lt IE 9]>
<script type="text/javascript" src="/Public/Admin/lib/html5.js"></script>
<script type="text/javascript" src="/Public/Admin/lib/respond.min.js"></script>
<script type="text/javascript" src="/Public/Admin/lib/PIE_IE678.js"></script>
<![endif]-->
<link rel="stylesheet" type="text/css" href="/Public/Admin/lib/static/h-ui/css/H-ui.min.css" />
<link rel="stylesheet" type="text/css" href="/Public/Admin/lib/static/h-ui.admin/css/H-ui.admin.css" />
<link rel="stylesheet" type="text/css" href="/Public/Admin/lib/Hui-iconfont/1.0.7/iconfont.css" />
<link rel="stylesheet" type="text/css" href="/Public/Admin/css/sty.css">
<link rel="stylesheet" type="text/css" href="/Public/Admin/lib/dist/jquery-editable-select.min.css">
<!--[if IE 6]>
<script type="text/javascript" src="http://lib.h-ui.net/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<!--/meta 作为公共模版分离出去-->

<style type="text/css">
	.f-w{font-weight: bold;}
    td{font-size: 14px !important}
    .page-container{margin-bottom: 25px}
    button{margin-left: 20px }
    /*input,textarea,.Wdate{background-color: #fbfbfb !important}*/
    .textarea{height: 70px;width: 90%}
    .wq5{margin-top: 10px;margin-bottom: 10px;}
    /*.date1{padding-left: 27px !important}*/
    .textarea1{margin-top: 10px;}
    .a_c{float: right;padding-right: 100px;padding-top: 20px;color: blue}
    /*new*/
    .wid1{width: 18%;}
    .btn{width: 80px !important;margin: 15px;}
    .es-input{border-width:1px !important;line-height:2.1 !important;padding-right:46px !important;}
    .del-input{display:none;}
    .change-background{background:red !important;}
</style>
</head>


<body>
<div class="page-container">
    <!--<div class="mt-20 wq5" style="padding-bottom: 12px !important;padding-top: 12px !important">-->
    <form action="" method="post" class="form form-horizontal" id="form-article-add">
        <div class="row cl" id="main">
            <label class="form-label col-xs-3 col-sm-3">中介公司：</label>
            <div class="formControls col-xs-7 col-sm-7">
                <select id="company-select" class="form-control input-text" style="width:600px;" placeholder="请输入关键字进行筛选">
                    <?php if(is_array($companyList)): $i = 0; $__LIST__ = $companyList;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$val): $mod = ($i % 2 );++$i;?><option value="<?php echo ($val["id"]); ?>"><?php echo ($val["company_name"]); ?></option><?php endforeach; endif; else: echo "" ;endif; ?>
                </select>
                <input type="text" id="company-input" name="companyInput" />  <!-- 中介公司id -->
                <input type="text" id="company-type"  name="companyType" />  <!-- 中介公司添加来源 选择/新增 -->
                <input type="button" value="新增" id="company-change" onclick="addCompany()" class="btn btn-success radius"/>
            </div>
        </div>


        <div class="row cl" id="main">
            <label class="form-label col-xs-3 col-sm-3">门店：</label>
            <div class="formControls col-xs-7 col-sm-7">
                <select id="shop-select" class="form-control input-text" style="width:600px;" placeholder="请输入关键字进行筛选">
                </select>
                <input type="text" id="shop-input" name="shopInput" />  <!-- 门店买id -->
                <input type="text" id="shop-type"  name="shopType" />  <!-- 门店买添加来源 选择/新增 -->
                <input type="button" value="新增" id="shop-change" onclick="addShop()" class="btn btn-success radius"/>
            </div>
        </div>
        <div class="row cl shop-info" style="display:none">
            <label class="form-label col-xs-3 col-sm-3">店长：</label>
            <div class="formControls col-xs-7 col-sm-7">
                <input type="text" id="shop_manager" name="shop_manager" class="input-text" placeholder="请输入店长" >
            </div>
        </div>
        <div class="row cl shop-info" style="display:none">
            <label class="form-label  col-xs-3 col-sm-3" >店庆时间：</label>
            <div class="formControls col-xs-7 col-sm-7">
                <input type="text" id="shop_birthday" name="shop_birthday" class="input-text Wdate" placeholder="请选择店庆时间" style="width:180px;" onfocus="WdatePicker()">
            </div>
        </div>
        <div class="row cl shop-info" style="display:none">
            <label class="form-label  col-xs-3 col-sm-3" >门店地址：</label>
            <div class="formControls col-xs-7 col-sm-7">
                <input type="text" id="location" name="location" onclick="choice()" class="input-text" placeholder="请输入地址" >
                <input type="text" name="longitude" value="" />
                <input type="text" name="latitude" value="" />
            </div>
        </div>
        

        <div class="row cl" id="main">
            <label class="form-label col-xs-3 col-sm-3">经办人：</label>
            <div class="formControls col-xs-7 col-sm-7">
                <select id="agent-select" class="form-control input-text" style="width:600px;" placeholder="请输入关键字进行筛选">
                </select>
                <input type="hidden" id="agent-input" name="agentInput" class="input-text"  style="width:600px;" placeholder="请输入新增的经办人"/>  <!-- 经办人传值表单 -->
                <input type="button" value="新增" id="agent-change" onclick="addAgent()" class="btn btn-success radius"/>
            </div>
        </div>        
        <div class="row cl agent-info" style="display:none">
            <label class="form-label  col-xs-3 col-sm-3" >联系电话：</label>
            <div class="formControls col-xs-7 col-sm-7">
                <input type="text" id="tel" name="tel" class="input-text" placeholder="请输入联系电话" >
            </div>
        </div>
        <div class="row cl agent-info" style="display:none">
            <label class="form-label  col-xs-3 col-sm-3" >QQ：</label>
            <div class="formControls col-xs-7 col-sm-7">
                <input type="text" id="qq" name="qq" class="input-text" placeholder="请输入QQ号码" >
            </div>
        </div>
        <div class="row cl agent-info" style="display:none">
            <label class="form-label  col-xs-3 col-sm-3" >微信：</label>
            <div class="formControls col-xs-7 col-sm-7">
                <input type="text" id="wechat" name="wechat" class="input-text" placeholder="请输入微信号" >
            </div>
        </div>
        <div class="row cl agent-info" style="display:none">
            <label class="form-label  col-xs-3 col-sm-3" >Email：</label>
            <div class="formControls col-xs-7 col-sm-7">
                <input type="text" id="email" name="email" class="input-text" placeholder="请输入邮箱地址" >
            </div>
        </div>
        <div class="row cl">
            <label class="form-label  col-xs-3 col-sm-3" >备注：</label>
            <div class="formControls col-xs-7 col-sm-7">
                <input type="text" id="remark" name="remark" class="input-text" placeholder="请输入备注" >
            </div>
        </div>

        <div class="row cl">
            <div class="col-xs-7 col-sm-7 col-xs-offset-3 col-sm-offset-3" style="padding-left:0px !important">
                <button id="sub" onClick="zjtj()" class="btn btn-primary radius" type="button">添加</button>
                <?php if($id == ''): ?><button onclick="layer_close();" class="btn btn-default radius" type="button">取消</button>
                    <!-- <a class="btn btn-default radius" href='javascript:history.go(-1)'>取消</a> -->
                <?php else: ?>
                    <button onclick="quxiao()" class="btn btn-default radius" type="button">取消</button>
                    <!-- <a class="btn btn-default radius" href="<?php echo U('Client/quxiao',array('id'=>$id));?>">取消</a> --><?php endif; ?>
            </div>
        </div>
    </form>
    <!--</div>-->
</div>

<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="/Public/Admin/lib/jquery/1.9.1/jquery.min.js"></script> 
<script type="text/javascript" src="/Public/Admin/lib/layer/2.1/layer.js"></script> 
<script type="text/javascript" src="/Public/Admin/lib/static/h-ui/js/H-ui.js"></script> 
<script type="text/javascript" src="/Public/Admin/lib/static/h-ui.admin/js/H-ui.admin.js"></script> 
<script type="text/javascript" src="/Public/Admin/lib/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript" src="/Public/Admin/lib/dist/jquery-editable-select.js"></script>
<!--/_footer 作为公共模版分离出去-->

</body>

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript"> 
    
    $(document).ready(function() {
        $('#company-select').editableSelect().on('select.editable-select', function (e, li) {
            $('#last-company-selected').html(li.val() + '. ' + li.text());
            $('#company-input').val( li.val() );
            $.ajax({
                url : "<?php echo U('Client/getShop');?>",   // 如果$id为真，则表示修改此条客户
                type: "POST",  
                data: {'companyId':li.val()},
                success: function(msg){  
                    // console.log(msg);
                    if(msg['state'] == 200){
                        var content = '';
                        for (var i = 0; i < msg['content'].length; i++) {
                            content += "<li class='es-visible' style='display:block' value='"+ msg['content'][i]['id'] +"'>"+msg['content'][i]['shop_name']+"</li>";
                        }
                        $('.es-list:eq(1)').html(content);
                    }
                } 
            });
        });

        $('#shop-select').editableSelect().on('select.editable-select', function (e, li) {
            $('#last-shop-selected').html(li.val() + '. ' + li.text());
            $('#shop-input').val( li.val() );
            $.ajax({
                url : "<?php echo U('Client/getAgent');?>",   // 如果$id为真，则表示修改此条客户
                type: "POST",  
                data: {'shopId':li.val()},
                success: function(msg){  
                    // console.log(msg);
                    if(msg['state'] == 200){
                        var content = '';
                        for (var i = 0; i < msg['content'].length; i++) {
                            content += "<li class='es-visible' style='display:block' value='"+ msg['content'][i]['id'] +"'>"+msg['content'][i]['agent_name']+"</li>";
                        }
                        $('.es-list:eq(2)').html(content);
                    }
                } 
            });
        });

        $('#agent-select').editableSelect().on('select.editable-select', function (e, li) {
            $('#last-agent-selected').html(li.val() + '. ' + li.text());
            $('#agent-input').val( li.val() );
        });
    });

    // 新增中介公司 
    function addCompany(){
        layer.open({
            type: 2,
            title: '新增中介公司',
            shadeClose: true,
            //shade: 0.8,
            area: ['600px', '350px'],
            content: '<?php echo U("Client/addCompany");?>' 
        }); 
    }

    // 门店 选择和手动填写 切换
    function addShop(){
        if($('#shop-change').val() == '新增'){
            // 门店 表单处理
            $('#shop-select').val('');
            $('#shop-select').addClass('del-input');
            $('#shop-input').val('');
            $('#shop-input').attr('type','text');
            $('#shop-change').val('选择');
            $('#shop-change').addClass('change-background');
            $('.shop-info').css('display','block');
            // 经办人 表单处理
            $('#agent-select').val('');
            $('#agent-select').addClass('del-input');
            $('#agent-input').val('');
            $('#agent-input').attr('type','text');
            $('#agent-change').addClass('del-input');
            $('.agent-info').css('display','block');
        }else{
            // 门店 表单处理
            $('#shop-select').removeClass('del-input');
            $('#shop-input').val('');
            $('#shop-input').attr('type','hidden');
            $('#shop-change').val('新增');
            $('#shop-change').removeClass('change-background');
            $('.shop-info').css('display','none');
            // 经办人 表单处理
            $('#agent-select').removeClass('del-input');
            $('#agent-input').val('');
            $('#agent-input').attr('type','hidden');
            $('#agent-change').removeClass('del-input');
            $('.agent-info').css('display','none');
        }
    }

    // 经办人 选择和手动填写 切换
    function addAgent(){
        if($('#agent-change').val() == '新增'){
            // 经办人 表单处理
            $('#agent-select').val('');
            $('#agent-select').addClass('del-input');
            $('#agent-input').val('');
            $('#agent-input').attr('type','text');
            $('#agent-change').val('选择');
            $('#agent-change').addClass('change-background');
            $('.agent-info').css('display','block');
        }else{
            // 经办人 表单处理
            $('#agent-select').removeClass('del-input');
            $('#agent-input').val('');
            $('#agent-input').attr('type','hidden');
            $('#agent-change').val('新增');
            $('#agent-change').removeClass('change-background');
            $('.agent-info').css('display','none');
        }
    }

    // 选择门店地址
    function choice(){ 
        window.location.href = "<?php echo U('Client/choiceAddress');?>";
        // $.ajax({  
        //     url: "<?php echo U('Client/addCheck');?>", 
        //     type: "POST",  
        //     data: $('form').serializeArray(), 
        //     success: function(msg){ 
        //         console.log(msg);
        //         // if(msg['state'] == 200){
        //         //     layer.msg(msg['content'],{icon:1,time:1000});
        //         //     var url = "<?php echo U('Client/choiceAddress',array('id'=>'clientid'));?>";
        //         //     url = url.replace('clientid',msg['id']);
        //         //     window.location.href = url;
        //         // }else{
        //         //     layer.msg(msg['content'],{icon:2,time:1000});
        //         //     $('#location').attr('onclick','zjtj()');
        //         // }
        //     }  
        // });
    }


    // 添加客户
    function zjtj(){
        if( $.trim($('#client_name').val()) == '' ){ 
            layer.msg('请先输入客户名称',{icon:2,time:1000});
        }else{
            $('#sub').attr('onclick','');
            $.ajax({  
                url: "<?php echo U('Client/addCheck',array('id'=>$id));?>",   // 如果$id为真，则表示修改此条客户
                type: "POST",  
                data: $('form').serializeArray(), 
                success: function(msg){  
                    //console.log(msg);
                    if(msg['state'] == 200){
                        layer.msg(msg['content'],{icon:1,time:1000});
                        setTimeout('parent.location.href = "<?php echo U('Client/index');?>"', 1000);
                    }else{
                        layer.msg(msg['content'],{icon:2,time:1000});
                        $('#sub').attr('onclick','zjtj()');
                    }
                }  
            });
        }   
    }

    // 添加负责人  
    function tjfzr(){
        if( $.trim($('#client_name').val()) == '' ){ 
            layer.msg('请先输入客户名称',{icon:2,time:1000});
        }else{
            $('#add-fzr').attr('onclick','');
            $.ajax({  
                url: "<?php echo U('Client/addCheck',array('id'=>$id));?>", 
                type: "POST",  
                data: $('form').serializeArray(), 
                success: function(msg){ 
                    //console.log(msg);
                    if(msg['state'] == 200){
                        layer.msg(msg['content'],{icon:1,time:1000});
                        var url = "<?php echo U('Client/contactAdd',array('cid'=>'clientid'));?>";
                        url = url.replace('clientid',msg['id']);
                        window.location.href = url;
                    }else{
                        layer.msg(msg['content'],{icon:2,time:1000});
                        $('#add-fzr').attr('onclick','zjtj()');
                    }
                }  
            });
        }
        
    }

    // 取消
    function quxiao(){
        $.ajax({  
            url: "<?php echo U('Client/quxiao',array('id'=>$id));?>", 
            success: function(msg){ 
                //console.log(msg);
                if(msg['state'] == 200){
                    layer_close();
                }else{
                    layer.msg(msg['content'],{icon:2,time:1000});
                }
            }  
        });
    }

</script>

</html>